﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;

namespace CTEA_INDIA
{
    public partial class Audition_Artist : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BAL.conn.connectionString = ConfigurationManager.ConnectionStrings["CTEA"].ConnectionString;
            if (!IsPostBack)
            {
                if (Session["UserID"] == null)
                {
                    Response.Redirect("Default.aspx");
                }
            }

            if (Request.QueryString["AudiID"] != null)
            {
                int AuditionID = Convert.ToInt32(Request.QueryString["AudiID"]);
                ViewState["AuditionID"] = AuditionID;

            }

            populateArtist();
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string AuditionID = Convert.ToString(ViewState["AuditionID"]);
            string ArtistName = txtArtistName.Text;
            DateTime Bdate = Convert.ToDateTime(txtBDate.Text);
            string Address = txtAddress.Text;
            string ContNo = txtContNum.Text;
            string Commitment = ddlCommitment.SelectedValue;
            string location = txtLocation.Text ;
            string referto = ddlRefer.SelectedValue;
            string feedback = txtFeedback.Text;

            BAL.Customers.InsertAuditionArtist(AuditionID, ArtistName, Bdate, Address, ContNo, Commitment, location, referto, feedback);
            populateArtist();

            txtArtistName.Text = "";
            txtAddress.Text = "";
            txtContNum.Text = "";
            txtFeedback.Text = "";

        }

        public void populateArtist()
        {
            int AudiID = Convert.ToInt32(ViewState["AuditionID"]);
            DataSet ds = BAL.Customers.viewallAudtionArtist(AudiID);
            grdArtistSheet.DataSource = ds;
            grdArtistSheet.DataBind();

        }

        protected void lnkView_Click(object sender, EventArgs e)
        {
            LinkButton lnkVw = sender as LinkButton;
            GridViewRow row = (GridViewRow)lnkVw.Parent.Parent;
            int ArtistID = Convert.ToInt32(grdArtistSheet.DataKeys[row.RowIndex]["AudtionArtistID"]);
            string[] Details = BAL.Customers.GetAudtionArtistById(ArtistID);
            lblName.Text = Details[2];
            DateTime dt = Convert.ToDateTime(Details[3]);
            int age = (int)((DateTime.Now - dt).TotalDays / 365.255);
            lblBirthDate.Text = age.ToString();
            lblAddress.Text = Details[4];
            lblContactNo.Text = Details[5];
            lblCommitment.Text = Details[6];
            lbllocation.Text = Details[7];
            lblReferTo.Text = Details[8];
            lblFeedback.Text = Details[9];

            lnkView_ModalPopupExtender.Show();
        }



        protected void lnkEdit_Click(object sender, EventArgs e)
        {
            LinkButton lnkEdit = sender as LinkButton;
            GridViewRow row = (GridViewRow)lnkEdit.Parent.Parent;

            int Cid = Convert.ToInt32(grdArtistSheet.DataKeys[row.RowIndex]["AudtionArtistID"]);
            string[] Details = BAL.Customers.GetAudtionArtistById(Cid);
            ViewState["AudtionArtistID"] = Cid.ToString();

            txtEdtArtistName.Text = Details[2];
            txtEdtDOB.Text = DateTime.Parse(Details[3]).ToShortDateString();
            txtEdtAddr.Text = Details[4];
            txtEdtContact.Text = Details[5];
            cmbEdtCommit.SelectedValue = Details[6];
            txtEdtLocation.Text = Details[7];
            cmbEdtRefer.SelectedValue = Details[8];
            txtEdtFeedback.Text = Details[9];

            LnkEditPopUp.Show();

        }

        protected void lnkDelete_Click(object sender, EventArgs e)
        {
            LinkButton lnkEdit = sender as LinkButton;
            GridViewRow row = (GridViewRow)lnkEdit.Parent.Parent;

            int Cid = Convert.ToInt32(grdArtistSheet.DataKeys[row.RowIndex]["AudtionArtistID"]);
            BAL.Customers.DeleteAudtionArtistById(Cid);
            populateArtist();
        }

        protected void update(object sender, EventArgs e)
        {
            string AuditionID = ViewState["AudtionArtistID"].ToString();
            string ArtistName = txtEdtArtistName.Text;
            string Bdate = DateTime.Parse(txtEdtDOB.Text).ToShortDateString();
            string Address = txtEdtAddr.Text;
            string ContNo = txtEdtContact.Text;
            string Commitment = cmbEdtCommit.SelectedValue;
            string location = txtEdtLocation.Text;
            string referto = cmbEdtRefer.SelectedValue;
            string feedback = txtEdtFeedback.Text;

            BAL.Customers.UpdateAuditionArtist(AuditionID, ArtistName, Bdate, Address, ContNo, Commitment, location, referto, feedback);


            populateArtist();
        }


    }
}
